package com.example.by.test;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.Html;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import org.xml.sax.XMLReader;

import java.util.ArrayList;


public class MainActivity extends AppCompatActivity {
    private SwipeRefreshLayout layout;
    private ListView listView;
    private ArrayList s;
//    private Adapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.header);
        ImageView imageView = (ImageView) findViewById(R.id.circle);
        MaterialProgressDrawable progress = new MaterialProgressDrawable(getApplicationContext(), imageView);
        imageView.setImageDrawable(progress);
        progress.setBackgroundColor(0xFFFAFAFA);
        //圈圈颜色,可以是多种颜色
        progress.setAlpha(256);
        progress.setColorSchemeColors(0xFF000000);
        progress.start();
        Util.loadingAlert(MainActivity.this);
        CharSequence t=Html.fromHtml("<font>草莓</font><img src=‘strawberry'><font>草莓</font><img src=‘strawberry'><font>草莓</font><img src=‘strawberry'><font>草莓</font><img src=‘strawberry'>", new Html.ImageGetter() {
            @Override
            public Drawable getDrawable(String source) {
                Drawable draw=getResources().getDrawable(R.mipmap.strawberry);
                draw.setBounds(0, 0, draw.getIntrinsicWidth(), draw.getIntrinsicHeight());
                return draw;
            }
        }, new Html.TagHandler() {
            @Override
            public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {

            }
        });

        TextView textView= (TextView) findViewById(R.id.t);
        textView.setText(t);
        Handler handler=new Handler(){
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what){
                    case 0:
                    System.out.println("msg:"+msg.obj.toString());
                }
            }
        };
        new LoadingThread("test",handler).start();
        Window window=new Window(getApplicationContext());
//        init();
//        Listener listener = new Listener();
//        listener.setOnZbyListener(new Listener.ZbyListener() {
//            @Override
//            public void setRotate(int x) {
//                System.out.println("x:" + x);
//            }
//        });
    }


//    private void init() {
//        layout = (SwipeRefreshLayout) findViewById(R.id.layout);
//        layout.setOnRefreshListener(this);
//        listView = (ListView) findViewById(R.id.pullToRefresh);
//        s = new ArrayList();
//        for (int i = 1; i < 66; i++) {
//            s.add(new Random().nextDouble());
//        }
//        adapter = new Adapter();
//        listView.setAdapter(adapter);
//    }
//
//    @Override
//    public void onRefresh() {
//        System.out.println("refreshing");
//        handler.sendEmptyMessageDelayed(0, 2000);
//    }
//
//    Handler handler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            switch (msg.what) {
//                case 0:
//                    s.add(0, new Random().nextDouble());
//                    adapter.notifyDataSetChanged();
//                    layout.setRefreshing(false);
//
//            }
//        }
//    };

//    class Adapter extends BaseAdapter {
//        @Override
//        public int getCount() {
//            return s.size();
//        }
//
//        @Override
//        public Object getItem(int position) {
//            return s.get(position);
//        }
//
//        @Override
//        public long getItemId(int position) {
//            return position;
//        }
//
//        @Override
//        public View getView(int position, View convertView, ViewGroup parent) {
//            TextView textView = new TextView(getApplicationContext());
//            textView.setText(s.get(position) + "");
//            textView.setTextColor(Color.BLACK);
//            return textView;
//        }
//    }
}
